package com.mavenq.fly.business.controller;

import com.mavenq.fly.business.service.AsyncTask;
import com.mavenq.fly.business.service.AsyncTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/async")
@Slf4j
public class AsyncTaskController {

    @Autowired
    private AsyncTask asyncTask;
    @Autowired
    private AsyncTaskService service;

    @GetMapping(value = "/test")
    public Object test() {
        for (int i = 0; i < 20; i++) {
            asyncTask.register();
        }
        System.out.println("主线程结束");
        return "OK";
    }

    @GetMapping(value = "/test1")
    public Object test1() throws InterruptedException {
        service.asyncTask();
        service.syncTask();
        System.out.println("主线程结束");
        return "OK";
    }

}